package org.raymond.iworks.study.basic.designpattern.principle.demeter;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

public class Demeter2 {
    public static void main(String[] args) {
        SchoolManager2 schoolManager = new SchoolManager2();
        schoolManager.printAllEmployee(new CollegeManager2());
    }
}

@Setter
@Getter
class Employee2{
    private String id;
}

@Setter
@Getter
class CollegeEmployee2{
    private String id;
}
class CollegeManager2{
    public List<CollegeEmployee2> getAllEmployee(){
        List<CollegeEmployee2> list = new ArrayList<>();
        for(int i=0; i<10; i++){
            CollegeEmployee2 emp = new CollegeEmployee2();
            emp.setId("学院员工id="+i);
            list.add(emp);
        }
        return list;
    }

    public void printAllEmployee(){
        List<CollegeEmployee2> list1 = this.getAllEmployee();
        System.out.println("--- 学院员工 ---");
        for(CollegeEmployee2 e : list1){
            System.out.println(e.getId());
        }
    }
}

/**
 * schoolManager的直接朋友: Employee, CollegeManager
 * CollegeEmployee不是直接朋友,而是一个陌生类,违背了迪米特法则.
 */
class SchoolManager2{
    public List<Employee2> getAllEmployee(){
        List<Employee2> list = new ArrayList<>();
        for(int i=0; i<5; i++){
            Employee2 emp = new Employee2();
            emp.setId("学校总部员工id="+i);
            list.add(emp);
        }
        return list;
    }
    public void printAllEmployee(CollegeManager2 sub){
        sub.printAllEmployee();

        List<Employee2> list2 = this.getAllEmployee();
        System.out.println("--- 总部员工 ---");
        for(Employee2 e : list2){
            System.out.println(e.getId());
        }
    }
}